home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SIGGRAPH 2002: Conference Proceedings
/
SIGGRAPH 2002: Conference Proceedings.iso
/
pc
/
supplemental_material
/
kalnins
/
paper-effect.txt
Wrap
Text File
|
2002-05-10
|
4KB
|
115 lines
// Register Combiner Program for media simulation in WYSISYG NPR
// =============================================================
//
// This program implements the "paper effect" algorithm described in:
//
// WYSIWYG NPR: Drawing Strokes Directly on 3D Models.
// by Robert D. Kalnins, Lee Markosian, Barbara J. Meier,
// Michael A. Kowalski, Joseph C. Lee, Philip L. Davidson,
// Matthew Webb, John F. Hughes and Adam Finkelstein.
// SIGGRAPH 2002.
//
// The pixel's incoming color (p) and alpha (a) are derived as a
// 'GL_MODULATE' of Texture0 and Primary Color. The outgoing color
// (p') is simply p (unchanged). Howver, outgoing alpha (a') is
// computed as a' = t(h,a), where h is the 'height' of the paper
// (Texture1 alpha channel), and t(h,a) is described both below and
// in the paper. Typically, the Texture1 UV coordinate of the
// incoming fragment is derived from its screen-space position, so
// that the paper texture can be thought of as a media surface fixed
// to the viewing window. This can be achieved by a trivial vertex
// program that accounts for hardware perspective correction.
//
// For convenience, the user can adjust the 'brightness' (b) and
// 'contrast' (c) of the paper texture using methods taken from:
//
// P. Haeberli, D. Voorhies.
// Image Processing by Linear Interpolation and Extrapolation.
// Iris Universe, (28):8-9, 1994.
// http://www.sgi.com/grafica/interp/
//
// Both b and c are in [0,1], with value 0.5 causing no effect.
//
// In terms of the notation in the reference:
//
// alpha = 2b or 2c and mean luminance is 0.5
//
// In terms of the program below, b & c map h to h' as
//
// h' = (0.5 - c) + (2c)(2b)h
//
// Register Combiner Program comments:
//
// Tex0 binds stroke or object texture (generally in RGBA channels)
// and this program performs GL_MODULATE (Tex0 * Col0) to give
// incoming pigment color (p) and alpha (a)
//
// Tex1 binds paper height (h) (in the alpha channel -- mean height 0.5)
//
// As described in the paper, we use transfer functions to remap alpha:
// peak(a) = clamp(2a)
// valley(a) = clamp(2a - 1)
// t(h,a) = peak(a)h + valley(a)(1 - h)
//
// The final combiner outputs:
// color p' = p
// alpha a' = t(h',a)
//
// Stage 0:
// RGB: (Alpha computation in BLUE channel)
// Spare1[B] = h' = (0.5 - c) + (2c)(2b)h
// Alpha:
// a = Col0*Tex0
// Spare0[A] = peak(a)
// Spare1[A] = valley(a)
// Stage 1:
// RGB:
// Spare0'[RGB] = p = Col0*Tex0
// Alpha:
// Spare0'[A] = a' = h'* peak(a) + (1-h') * valley(a)
// = Spare1[B] * Spare0[A] + (1-Spare1[B]) * Spare1[A]
// Final:
// Output[RGB] = p' = p = Spare0'[RGB]
// Output[A] = a' = t(h,a) = Spare0'[A]
//
// Note: register combiner Const1 must hold 2bc, but this must be
// clamped to [0,1]. So, if b > 0.5, the product is remapped into [0,1]
// as below. The end result is that if c,b > 0.5, the effect of b is
// diminished...
CONSTRAST = c;
TWO_X_CONTRAST_X_BRIGHTNESS = (b<=0.5)?(2.0*c*b):(c+(1.0-c)*(b-0.5)/0.5);
// **begin** nvparse Register Combiner Program string
!!RC1.0
const0 = (0.000000, 0.000000, 0.000000, CONTRAST );
const1 = (0.000000, 0.000000, 0.000000, TWO_X_CONTRAST_X_BRIGHTNESS);
{
rgb {
discard = -half_bias(const0.a) * -half_bias(zero.a);
discard = unsigned(const1.a) * unsigned(tex1.a);
spare1 = sum();
scale_by_two();
}
alpha {
spare0 = unsigned(col0) * unsigned(tex0);
discard = unsigned_invert(zero) * half_bias(zero);
spare1 = sum();
scale_by_two();
}
}
{
rgb {
spare0 = unsigned(col0) * unsigned(tex0);
}
alpha {
discard = unsigned(spare0) * unsigned(spare1.b);
discard = unsigned(spare1) * unsigned_invert(spare1.b);
spare0 = sum();
}
}
out.rgb = spare0;
out.a = spare0;
// **end** nvparse Register Combiner Program string